// dfs + visited
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let n;
let initArr = [];
rl.on("line", (line)=>{
    if(n === undefined) {
        n = Number(line.trim())
    } else {
       let temp = line.trim().split(" ").map(Number)
        initArr.push(temp)

        if(initArr.length === n) {
            console.log(getResult(n, initArr));

            // clear
            n = undefined;
            initArr.length = 0
        }
    }
})

/**
 * 计算不联通的站点数
 * @param n {number} station count
 * @param initArr  {[[number]]}
 * @return {number} 不联通的站点数
 */
function getResult(n, initArr){
    const visited = new Array(n).fill(false);
    let count = 0;
    for (let i = 0; i < n; i++) {
        if(!visited[i]){
            dfs(i, initArr, visited)
            count++;
        }
    }
    return count;
}

function dfs(i, initArr, visited) {
    // 截止条件
    visited[i] = true;

    const arr = initArr[i]
    for (let j = 0; j < arr.length ; j++) {
        const num = arr[j];
        if(num === 1 && !visited[j]) {
            dfs(j, initArr, visited)
        }
    }
}